<?php

namespace App\Models\Oauth;

use Illuminate\Support\Facades\DB;
use App\Models\Model;
/**
 * 查询app_id相关信息
 */

class AppModel extends Model
{

    const TABLENAME = 'tw_open_app';

    const APP_STATUS_BAN = 1; //禁用
    const APP_STATUS_NOL = 0; //正常

    /**
     * 初始化并返回数据库请求构建器
     *
     * @return Illuminate\Support\Facades\DB::table(TABLENAME)
     */
    public static function dbTable()
    {
        return DB::table(self::TABLENAME);
    }

    public static function getAppById($id)
    {
        $where[] = ['id', '=', $id];
        $where[] = ['status', '=', self::APP_STATUS_NOL];
        return self::dbTable()
            ->select('id', 'app_key', 'app_secret', 'name', 'detail', 'member_id', 'domain', 'created', 'updated')
            ->where($where)
            ->first();
    }

    public static function getAppByAppKey($appKey)
    {
        $where['app_key'] = $appKey;
        $where['status'] = self::APP_STATUS_NOL;
        $appInfo = self::dbTable()
            ->select('id', 'app_key', 'app_secret', 'name', 'detail', 'member_id', 'domain', 'created', 'updated')
            ->where($where)
            ->first();
        return $appInfo;
    }

}

?>